package com.zzx.es;

import org.apache.http.HttpHost;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * @ClassName: com.zzx.es.ESTest_Client
 * @Description: ES文档删除测试类
 * @Author zhouzhixin
 * @Date 2021/8/13
 * @Version 1.0
 */
public class ESTest_Doc_Delete {
    public static void main(String[] args) {
        // 建立可自动关闭的连接
        try (RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("127.0.0.1", 9200, "http"))
        )) {
            // 删除数据
            DeleteRequest request = new DeleteRequest();
            request.index("user").id("1001");
            // 发送请求
            DeleteResponse response = client.delete(request, RequestOptions.DEFAULT);
            // 返回结果
            System.out.println(response.getResult());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
